package com.pro.beans;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Menu {
	private static Map<String,Menu[]> menuMap = new  HashMap<String,Menu[]>();
	private String name;
	private String url;
	private String id;
	private Integer type;
	
	
	public static Menu[] getMenuById(String id,Integer type){
		Menu[] menus = menuMap.get(id);
		List<Menu> menuList = new ArrayList<Menu>();
		for(Menu menu:menus){
			if(type==null){
				type=0;
			}
			if(menu!=null&&menu.getType()<=type){
				menuList.add(menu);
			}
		}
		Menu[] meu = new Menu[menuList.size()];
		return (Menu[])menuList.toArray(meu);
	}
	
	public Integer getType() {
		return type;
	}
	public String getId() {
		return id;
	}
	public Menu(String url, String name) {
		super();
		this.name = name;
		this.url = url;
	}
	public Menu(String url, String name,String id,Integer type) {
		super();
		this.name = name;
		this.url = url;
		this.id = id;
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public String getUrl() {

		return url;
	}

	static {
		Menu[] arr = new Menu[] { 
				new Menu("index.do?jspName=alarmList&menuId=1", "警情总览","alarmList",0), 
				new Menu("index.do?jspName=alarmType&menuId=1&type=1", "火灾报警","alarmType1",0) ,
				new Menu("index.do?jspName=alarmType&menuId=1&type=2", "设备报警","alarmType2",0) ,
				new Menu("index.do?jspName=alarmType&menuId=1&type=3", "电器报警","alarmType3",0) }
				;
		// leftMenuList.addAll(Arrays.asList(arr));
		menuMap.put("1",arr);
		Menu[] arr2 = new Menu[] { 
				new Menu("index.do?jspName=gridInfo&menuId=2", "网格信息","gridInfo",1), 
				new Menu("index.do?jspName=polling&menuId=2", "巡检任务","polling",1) ,
				new Menu("index.do?jspName=gridnews&menuId=2", "网格公告","gridnews",1)};
		// leftMenuList.addAll(Arrays.asList(arr));
		menuMap.put("2",arr2);
		Menu[] arr3 = new Menu[] { 
				new Menu("index.do?jspName=addGrid&menuId=3", "添加网格","addGrid",1), 
				new Menu("index.do?jspName=addFirePerson&menuId=3", "添加人员","addFirePerson",1)};
		// leftMenuList.addAll(Arrays.asList(arr));
		menuMap.put("3",arr3);
		Menu[] arr4 = new Menu[] { 
				new Menu("index.do?jspName=userList&menuId=4", "用户管理","userList",2),
				new Menu("index.do?jspName=userinfo&menuId=4", "个人信息","userinfo",0),
				new Menu("index.do?jspName=modifyPassword&menuId=4", "修改密码","modifyPassword",0),
				};
		// leftMenuList.addAll(Arrays.asList(arr));
		menuMap.put("4",arr4);
	}
	// leftMenuList.addAll();
}